package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.Adapter.SearchAdapter;
import com.example.yuejianapp14.Activity.JavaBean.Search;
import com.example.yuejianapp14.Activity.Listener.SearchListener;
import com.example.yuejianapp14.Activity.Model.SearchModel;
import com.example.yuejianapp14.R;

import java.util.List;

public class SearchActivity extends AppCompatActivity implements View.OnClickListener,View.OnKeyListener {
    private EditText serach;
    private ImageButton zsfind;
    private RecyclerView recyclerview;
    private Context mContext;

    SearchListener searchListener = new SearchListener() {
        @Override
        public void onResponse(List<Search> beanList) {
            if (beanList.size()==0){
                Toast.makeText(SearchActivity.this,"没有你想搜索的东西！", Toast.LENGTH_SHORT).show();
            }else {
                recyclerview.setAdapter(new SearchAdapter(SearchActivity.this,beanList));
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        initView();
        initEvent();
        zsfind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchModel serachModel = new SearchModel();
                serachModel.search(serach.getText().toString(),searchListener);
            }
        });
    }

    private void initEvent() {
        serach.setOnKeyListener(this);
    }

    private void initView() {
        serach = (EditText)findViewById(R.id.zssearch);
        zsfind=(ImageButton)findViewById(R.id.zsfind);
        recyclerview = (RecyclerView)findViewById(R.id.rv_search);
        recyclerview.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {

        return false;
    }

}
